package com.ruoyi.web.controller.check;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.check.domain.Overtime;
import com.ruoyi.check.service.IOvertimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加班管理Controller
 * 
 * @author tza
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/check/overtime")
public class OvertimeController extends BaseController
{
    @Autowired
    private IOvertimeService overtimeService;

    /**
     * 查询加班管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:list')")
    @GetMapping("/list")
    public TableDataInfo list(Overtime overtime)
    {
        startPage();
        List<Overtime> list = overtimeService.selectOvertimeList(overtime);
        return getDataTable(list);
    }

    /**
     * 导出加班管理列表
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:export')")
    @Log(title = "加班管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Overtime overtime)
    {
        List<Overtime> list = overtimeService.selectOvertimeList(overtime);
        ExcelUtil<Overtime> util = new ExcelUtil<Overtime>(Overtime.class);
        util.exportExcel(response, list, "加班管理数据");
    }

    /**
     * 获取加班管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:query')")
    @GetMapping(value = "/{otId}")
    public AjaxResult getInfo(@PathVariable("otId") Integer otId)
    {
        return success(overtimeService.selectOvertimeByOtId(otId));
    }

    /**
     * 新增加班管理
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:add')")
    @Log(title = "加班管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Overtime overtime)
    {
        return toAjax(overtimeService.insertOvertime(overtime));
    }

    /**
     * 修改加班管理
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:edit')")
    @Log(title = "加班管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Overtime overtime)
    {
        return toAjax(overtimeService.updateOvertime(overtime));
    }

    /**
     * 删除加班管理
     */
    @PreAuthorize("@ss.hasPermi('check:overtime:remove')")
    @Log(title = "加班管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{otIds}")
    public boolean remove(@PathVariable Integer[] otIds)
    {
        //return toAjax(overtimeService.deleteOvertimeByOtIds(otIds));
        return overtimeService.deleteOvertimeByOtIds(otIds);
    }
}
